package com.goldgov.distancelearning.web;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.goldgov.authorityInfo.service.AuthorityInfoInit;
import com.goldgov.distancelearning.service.Distancelearning;
import com.goldgov.distancelearning.service.DistancelearningAttendance;
import com.goldgov.distancelearning.service.DistancelearningCourse;
import com.goldgov.distancelearning.service.DistancelearningCourseQuery;
import com.goldgov.distancelearning.service.DistancelearningQuery;
import com.goldgov.distancelearning.service.DistancelearningService;
import com.goldgov.distancelearning.service.DistancelearningUser;
import com.goldgov.distancelearning.service.DistancelearningUserQuery;
import com.goldgov.kcloud.core.json.JsonObject;
import com.goldgov.kcloud.core.json.JsonQueryObject;
import com.goldgov.kcloud.core.json.JsonSuccessObject;
import com.goldgov.login.web.model.LoginAuthUser;
import com.goldgov.utils.DateUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/** 
 * @ClassName: DistancelearningController 
 * @Description: TODO
 */
@RestController
@RequestMapping("/portal/distancelearning")
@Api("远程教育服务接口")
public class DistancelearningForPortalController {
	
	@Autowired
	private DistancelearningService distancelearningService;
	
	
	/**
	 * 查询远程教育录播记录
	 * @date 2018年6月22日 下午4:33:00 
	 * @author hanxiangyu
	 * @param query
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("/getLBList")
	@ApiOperation(value = "远程教育录播记录", notes ="查询已参加的和创建的记录")
	@ApiImplicitParams({ @ApiImplicitParam(name = "searchBeginDate", value = "开始时间", paramType = "query"),
		 @ApiImplicitParam(name = "searchEndDate", value = "结束", paramType = "query"),
		 @ApiImplicitParam(name = "searchYear", value = "年份", paramType = "query"),
		 @ApiImplicitParam(name = "searchQuqrter", value = "季度", paramType = "query"),
		 @ApiImplicitParam(name = "searchDName", value = "会议名称", paramType = "query"),
		 @ApiImplicitParam(name = "searchParentId", value = "管理范围", paramType = "query"),
		 @ApiImplicitParam(name = "searchIsInclude", value = "是否包含下级单位", paramType = "query") })
	public JsonQueryObject<Distancelearning> getLBListByAdmin(@ApiIgnore DistancelearningQuery query,HttpServletRequest request,Model model){
		
		if (query.getSearchUserID() == null || "".equals(query.getSearchUserID())) {
			LoginAuthUser user = LoginAuthUser.getUser(request);
			query.setSearchUserID(user.getEntityID());
		}
		List<Distancelearning> list = distancelearningService.getLBList(query);
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}
	
	/**
	 * 查询远程教育
	 * @date 2018年6月22日 下午4:33:00 
	 * @author hanxiangyu
	 * @param query
	 * @param request
	 * @param model
	 * @return
	 */
	@GetMapping
	@ApiOperation(value = "远程教育记录", notes ="查询同级及同级以下记录")
	@ApiImplicitParams({ @ApiImplicitParam(name = "searchBeginDate", value = "开始时间", paramType = "query"),
		 @ApiImplicitParam(name = "searchEndDate", value = "结束", paramType = "query"),
		 @ApiImplicitParam(name = "searchYear", value = "年份", paramType = "query"),
		 @ApiImplicitParam(name = "searchQuqrter", value = "季度", paramType = "query")})
	public JsonQueryObject<Distancelearning> getDistancelearningList(@ApiIgnore DistancelearningQuery query,HttpServletRequest request,Model model){
//		String u=LoginAuthUser.getScopeCodeByFunctionID(AuthorityInfoInit.zbq,request);//后台获取code
		String u = LoginAuthUser.getScopeCodeByFunctionID(AuthorityInfoInit.ycjy,request);
		query.setSearchScopeCode(u);
		LoginAuthUser user=LoginAuthUser.getUser(request);
		query.setSearchUserID(user.getEntityID());//发布人id
		List<Distancelearning> list = distancelearningService.getDistancelearningList(query);
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}
	
	/**
	 * 获取已参加人员列表
	 * @date 2018年6月22日 下午4:33:10 
	 * @author hanxiangyu
	 * @param query
	 * @param request
	 * @param model
	 * @return
	 */
	@GetMapping("/listGetJoinUser")
	@ApiOperation(value = "获取已参加会议出席人列表", notes ="出席人列表查询")
	@ApiImplicitParams({ @ApiImplicitParam(name = "searchUserName", value = "用户姓名", paramType = "query"),
		@ApiImplicitParam(name = "searchDistancelearningID", value = "记录id", paramType = "query")})
	public JsonQueryObject<DistancelearningUser> getConferenceList(@ApiIgnore DistancelearningUserQuery query,HttpServletRequest request,Model model){
		List<DistancelearningUser> userList = distancelearningService.getDistancelearningUserList(query);
		query.setResultList(userList);
		return new JsonQueryObject<>(query);
	}
	
	/**
	 * 获取会议详情
	 * @date 2018年6月22日 下午4:33:48 
	 * @author hanxiangyu
	 * @param obj
	 * @param request
	 * @return
	 */
	@GetMapping("/getDistanceByID")
	@ApiOperation(value = "获取远程教育会议详情", notes ="获取远程教育会议详情")
	public JsonSuccessObject<Distancelearning> GetDistanceByID(Distancelearning obj,HttpServletRequest request){
		Distancelearning distaance = distancelearningService.getDistaanceByID(obj);
		JsonSuccessObject<Distancelearning> returnResult = new JsonSuccessObject<Distancelearning>(distaance);
		return returnResult;
	}
}
